#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int leastBricks(vector<vector<int>>& wall)
    {
        std::unordered_map<int, int> edgeCountMap;
        for (const auto& row : wall)
        {
            int n = row.size();
            int edge = 0;
            for (int i = 0; i < n - 1; ++i)
            {
                edge += row[i];
                ++edgeCountMap[edge];
            }
        }

        int high = wall.size();
        int ans = high;

        for (const auto& iter : edgeCountMap)
        {
            ans = std::min(ans, high - iter.second);
        }

        return ans;
    }
};